package cn.itrip.biz.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.ItripAreaDic;
import cn.itrip.beans.vo.ItripAreaDicVO;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.ErrorCode;
import cn.itrip.dao.service.ItripAreaDicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tequila
 **/
@Api("查询城市相关信息")
@RestController
@RequestMapping("/biz/api/hotel")
public class ItripAreaDicController {

    @Autowired
    private ItripAreaDicService itripAreaDicService;
    @ApiOperation(value = "根据参数isChina查询国内外热门城市",
            notes = "<p>传入参数isChina,生产hashMap自动填写参数,isHot,isChina查询到热门城市</p>" +
                    "<p>将数据封装到dto返回</p>",response =ItripAreaDicVO.class ,responseContainer = "dto",httpMethod = "GET")
    @GetMapping("/queryhotcity/{isChina}")
    public Dto queryHotCity(@PathVariable Integer isChina) {
        Map<String,Object> map = new HashMap<>();
        map.put("isHot",1);
        map.put("isChina",isChina);
        List<ItripAreaDicVO> voList = new ArrayList<>();

        try {
            List<ItripAreaDic> itripAreaDicList = itripAreaDicService.queryHotCity(map);
            for (ItripAreaDic itripAreaDic : itripAreaDicList) {
                ItripAreaDicVO vo = new ItripAreaDicVO();
                BeanUtils.copyProperties(itripAreaDic,vo);
                voList.add(vo);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常!", ErrorCode.SYSTEM_ERROR);
        }

        return DtoUtil.returnDataSuccess(voList);
    }

}
